<template>
   <div>
    <van-form @submit="register">
      <van-field
        v-model="user.phone"
        name="帐号"
        label="帐号"
        placeholder="帐号"
        :rules="[{ required: true, message: '请填写帐号' }]"
      />
      <van-field
        v-model="user.nickname"
        name="昵称"
        label="昵称"
        placeholder="昵称"
        :rules="[{ required: true, message: '请填写昵称' }]"
      />
      <van-field
        v-model="user.password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px;">
        <van-button round block type="info" native-type="primary">提交</van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
import {reqregister} from '../../http/http'

export default {
  data() {
    return {
      //1.初始化表单数据
      user: {
        phone: "",
        nickname: "",
        password: "",
      },
    };
  },
  methods:{
  // 2.点了注册按钮 
  register(){
    //发请求
    reqregister(this.user).then(res=>{
      console.log("请求完成");
      console.log(res);
      if(res.data.code===200){
        //注册成功
        alert(res.data.msg)
        //跳转到登录
        this.$router.push("/login")
      }else{
         // 注册失败
        alert(res.data.msg)
      }
    })
  }
}

}
</script>

<style>

</style>